<?php
$this->title="地址管理";
$this->context->bodyClass="page-order-address-list";
$defalutId = Yii::$app->request->get('uid');
?>
<!--加载样式-->
<?php $this->beginBlock('css');?>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="<?=Yii::getAlias('@static')?>/wap/liketry/css/cart.css">
<?php $this->endBlock();?>
<!--开始头部-->
<header>
    <div class="header-left" id="back"><span class="icon icon-arrow-left"></span></div>
    <h1>地址管理</h1>
</header>
<section class="order-address-list address-list" id="addressList">
	<?php if(count($info) > 0):?>
    <ul>
		<?php foreach($info as $val) :?>
			<li uid="<?=$val['uid']?>">
				<p><i><?=$val['consignee']?></i><i><?=$val['cell']?></i><br><i><?=$val['s1']?></i><i><?=$val['s2']?></i><i><?=$val['s3']?></i><br><i><?=$val['address']?></i></p>
				
				<div <?php if($val['is_default'] ==1)echo 'style="display:block"'?> class="address-default">默认</div>
				<?php if($val['is_default'] !=1) :?><div class="set-default">设为默认</div><?php endif;?>
				<div class="address-edit"><a href="<?=Yii::$app->urlManager->createUrl(["member-address/edit",'uid'=>$val['uid']]);?>"><span class="icon icon-edit"></span></a></div>
				<div class="address-del"><span class="icon icon-del"></span></div>
			</li>
		<?php endforeach;?>
    </ul>
	<?php else:?>
	<div class="noaddress">为了快递能更快更准确的给您派件，需要您重新填写的收货地址，给您造成不便敬请谅解</div>
    <?php endif ;?>
</section>
<div class="bottom-btn"><a href="<?=Yii::$app->urlManager->createUrl(["member-address/add"]);?>">+新增收货地址</a></div>
    <!--加载js-->
<?php $this->beginBlock('js');?>
<script src="<?= Yii::getAlias('@static') ?>/wap/common/js/zepto.min.js"></script>
<script src="<?= Yii::getAlias('@static') ?>/wap/common/js/fastclick.min.js"></script>
<script src="<?= Yii::getAlias('@static') ?>/wap/common/js/king.wap.js"></script>
<script>
	var addressDelUrl = '<?=Yii::$app->urlManager->createUrl(["member-address/del"]);?>';
	var setDefaultUrl = '<?=Yii::$app->urlManager->createUrl(['member-address/default']);?>
';
	$(function(){
		$("#back").on("click", function(){
			$.go(-1);
		});
		//删除地址
		$("#addressList").on("click", ".address-del", function(){
			addressDel($(this).closest("li"));
		}).on("click", ".set-default", function(){
			setDefault($(this).closest("li"));
		});
	})
	//删除地址
function addressDel(item){
	$.confirm("是否删除该地址？", function () {
		$.loader("加载中...");
		var uid = item.attr("uid");
		$.doAjax({
			url: addressDelUrl,
			data: {"uid": uid},
			success: function (data) {
				if(data.flag){
					$.tips("地址删除成功");
					item.remove();
				}
				$.loaded();
			}
		});
	});
}
//设为默认
function setDefault(item){
	$.loader("加载中...");
	var uid = item.attr("uid");
	$.doAjax({
		url: setDefaultUrl,
		data: {"uid": uid},
		success: function (data) {
			if(data.flag){
				$.tips("设置成功");
				item.children(".address-default").show();
				item.siblings().children(".address-default").hide();
			}
			$.loaded();
		}
	});
}
</script>
<?php $this->endBlock();?>